<?php

namespace app\common\model\user;

use app\admin\model\User;
use app\common\model\Course;
use app\common\model\Model;
use traits\model\SoftDelete;

class Order extends Model
{
    use SoftDelete;

    // 表名
    protected $name = 'user_order';

    // 追加属性
    protected $append = [
        'status_name',
    ];

    const STATUS = [
        self::STATUS_NON_PAY => '未支付',
        self::STATUS_SUCC => '已支付',
    ];

    const STATUS_SUCC = 1;
    const STATUS_NON_PAY = 0;

    public function getStatusNameAttr($value, $data)
    {
        return self::STATUS[$data['status']];
    }

    public function course()
    {
        return $this->belongsTo(Course::class, 'course_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
